//
//  Config.m
//  oschina_song
//
//  Created by song on 16/2/18.
//  Copyright © 2016年 song. All rights reserved.
//

#import "Config.h"
#import <UIKit/UIKit.h>
#import "SSKeychain.h"


NSString * const kService = @"OSChina";
NSString * const kAccount = @"account";
NSString * const kUserID = @"userID";

NSString * const kUserName = @"name";
NSString * const kPortrait = @"portrait";
NSString * const kPortraitURL = @"portraitURL";
NSString * const kUserScore = @"score";
NSString * const kFavoriteCount = @"favoritecount";
NSString * const kFanCount = @"fans";
NSString * const kFollowerCount = @"followers";

NSString * const kJoinTime = @"jointime";
NSString * const kDevelopPlatform = @"devplatform";
NSString * const kExpertise = @"expertise";
NSString * const kLocation = @"location";

NSString * const kTrueName = @"trueName";
NSString * const kSex = @"sex";
NSString * const kPhoneNumber = @"phoneNumber";
NSString * const kCorporation = @"corporation";
NSString * const kPosition = @"position";

NSString * const kTeamID = @"teamID";
NSString * const kTeamsArray = @"teams";



@implementation Config

+(void)saveOwnAccount:(NSString *)account andPasswd:(NSString *)passwd
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:account ?: @"" forKey:kAccount];
    [userDefaults synchronize];
    [SSKeychain setPassword:passwd ?: @"" forService:kService account:account];
    
}



+(void)saveProfile:(OSCUser *)user
{
    NSUserDefaults *userDefaults  = [NSUserDefaults standardUserDefaults];

    [userDefaults setInteger:user.userID forKey:kUserID];
    [userDefaults setObject:user.name forKey:kUserName];
    [userDefaults setURL:user.portraitURL forKey:kPortraitURL];
    [userDefaults setObject:@(user.score) forKey:kUserScore];
    [userDefaults setObject:@(user.favoriteCount) forKey:kFavoriteCount];
    [userDefaults setObject:@(user.fansCount) forKey:kFanCount];
    [userDefaults setObject:@(user.followersCount) forKey:kFollowerCount];
    
    [userDefaults synchronize];
}
+(int64_t)getOwnID
{
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
    
    return [userDefaults integerForKey:kUserID];
}

+(OSCUser *)myProfile
{
    OSCUser *user = [OSCUser new];
     NSUserDefaults *userDefaults  = [NSUserDefaults standardUserDefaults];
    
    user.userID = [userDefaults integerForKey:kUserID];
    user.name =[userDefaults objectForKey:kUserName];
    user.portraitURL =[userDefaults URLForKey:kPortraitURL];
    user.score = [[userDefaults objectForKey:kUserScore] intValue];
    user.favoriteCount =[[userDefaults objectForKey:kFavoriteCount] intValue];
    user.fansCount =[[userDefaults objectForKey:kFanCount] intValue];
    user.followersCount = [[userDefaults objectForKey:kFollowerCount] intValue];
    
    return  user;
}

+(void)clearProfile
{
    NSUserDefaults *userDefaults  = [NSUserDefaults standardUserDefaults];
    
    [userDefaults setInteger:@(0) forKey:kUserID];
    [userDefaults setObject:@"点击登录" forKey:kUserName];
    [userDefaults setObject:@(0) forKey:kUserScore];
    [userDefaults setObject:@(0) forKey:kFavoriteCount];
    [userDefaults setObject:@(0) forKey:kFanCount];
    [userDefaults setObject:@(0) forKey:kFollowerCount];
}

+(void)clearCookie
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults removeObjectForKey:@"sessionCookies"];
}
@end
